import java.util.*;


class ListNode {
    int val;
    ListNode next = null;
    public ListNode(int val) {
        this.val = val;
    }
}


public class Test3 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param head1 ListNode类 
     * @param head2 ListNode类 
     * @return ListNode类
     */
    public ListNode addInList (ListNode head1, ListNode head2) {
        // write code here
        int num1 = 0;
        int num2 = 0;

        if (head1 != null) {
            num1 = head1.val;
        }
        if (head2 != null) {
            num2 = head2.val;
        }

        ListNode cur1 = head1.next;
        ListNode cur2 = head2.next;

        while (cur1 != null) {
            num1 = num1 * 10 + cur1.val;
            cur1 = cur1.next;
        }

        while (cur2 != null) {
            num2 = num2 * 10 + cur2.val;
            cur2 = cur2.next;
        }

        int num3 = num1 + num2;
        String str = String.valueOf(num3);
        ListNode list = new ListNode(0);

        ListNode cur = list;
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            String s = String.valueOf(ch);
            ListNode node = new ListNode(Integer.parseInt(s));
            cur.next = node;
            cur = cur.next;
        }
        return list.next;
    }







}